﻿//========================================================= 
/**@file AndroidH003Installer.h
 * @brief Android下H003应用装载器
 * 
 * @date 2017-07-13   13:42:46
 * @author Zhyioo 
 * @version 1.0
 */ 
//--------------------------------------------------------- 
#ifndef _LIBZHOUYB_ANDROIDH003INSTALLER_H_
#define _LIBZHOUYB_ANDROIDH003INSTALLER_H_
//--------------------------------------------------------- 
#include "H003Installer.h"

#include "../../tools/IconvAppConvert.h"
using zhou_yb::application::tools::IDCardConvert;
using zhou_yb::application::tools::PbocTlvConvert;

#include "../../../extension/ability/idcard/AndroidWltDecoder.h"
using zhou_yb::extension::ability::AndroidWltDecoder;

#include "../device/JniCmdDriver.h"
#include "../device/InterrupterCmdDriver.h"
//--------------------------------------------------------- 
namespace zhou_yb {
namespace application {
namespace driver {
//--------------------------------------------------------- 
/// Android下H003模块安装
class AndroidH003Installer
{
protected:
    AndroidH003Installer() {}
public:
    static void Install(CommandRunner& runner, const char* devId = NULL)
    {
        H003Installer installer(runner);

        const char DEV_ID[] = "DEV";
        if(devId == NULL)
        {
            devId = DEV_ID;
        }
        CommandInstaller::RegisteNew<InterrupterCmdDriver<BoolInterrupter> >(runner, "Unit");
        CommandInstaller::RegisteNew<WltCmdDriver<AndroidWltDecoder> >(runner, "WLT");

        installer.InstallDEV<JniCmdDriver>(devId);
        installer.Install(devId);
        installer.InstallCipher(devId);

        CommandSetter setter(runner);
        setter.Registe(runner.Get(devId).Get("JniEnvCreate;JniEnvDispose"));

        CommandRunnerActuator actuator(runner);
        string scriptCmdName = "Script.";
        scriptCmdName += devId;
        scriptCmdName += ".OpenBindCMD";
        Ref<ComplexCommand> complexCmd = CommandInstaller::LookUp(runner, scriptCmdName.c_str());
        if(!complexCmd.IsNull())
        {
            complexCmd->OnCommand(actuator.Arg(), actuator.Result());
            actuator.Reset();
        }

        actuator.Set(devId).Run("IInteractiveTrans", true).Set("").Run("Select_IBaseDevice").Reset()
            .Run("IInteractiveTrans", true).Run("Select_IInteractiveTrans").Reset();

        pointer p = reinterpret_cast<pointer>(PbocTlvConvert::GbkToUTF8);
        actuator.Arg("TlvConvert", ArgConvert::ToString(p));
        actuator["PBOC"].Call("SetTlvConvert").Reset();

        p = reinterpret_cast<pointer>(IDCardConvert::UnicodeToUTF8);
        actuator.Arg("IdcConvert", ArgConvert::ToString(p));
        actuator["ID"].Call("SetIdcConvert").Reset();
    }
};
//--------------------------------------------------------- 
} // nemespace driver
} // namespace application
} // namespace zhou_yb
//--------------------------------------------------------- 
#endif // _LIBZHOUYB_ANDROIDH003INSTALLER_H_
//========================================================= 